﻿using System.Threading.Tasks;

namespace MvcFlow.StateStores
{
    public class SessionWorkflowStateStore : IWorkflowStateStore
    {
#pragma warning disable 1998
        public async Task<WorkflowState> Get(System.Web.Routing.RequestContext requestContext, string workflowName)
        {
            return requestContext.HttpContext.Session["workflow-" + workflowName.ToLowerInvariant()] as WorkflowState;
        }

        public async Task Put(System.Web.Routing.RequestContext requestContext, WorkflowState workflowState)
        {
            requestContext.HttpContext.Session["workflow-" + workflowState.Name.ToLowerInvariant()] = workflowState;
        }

        public async Task Delete(System.Web.Routing.RequestContext requestContext, WorkflowState workflowState)
        {
            requestContext.HttpContext.Session.Remove("workflow-" + workflowState.Name);
        }
#pragma warning restore 1998
    }
}